#include "Control_Value.h"

#include "RendererComponent.h"

using namespace gui;

Control_Value::Control_Value(CallbackGetFloatValue NewCallbackGetValue, std::string NewFormat, std::string NewCaption, Vec<2, float> NewFontSize, ColorRGBA<unsigned char> NewForeColor, ColorRGBA<unsigned char> NewBackColor, Vec<2, float> NewPos, Vec<2, float> NewSize, Control_Menu* NewParentMenu, Host& NewParentHost) :
Control_Text(NewCaption, NewFontSize, NewForeColor, NewBackColor, NewPos, NewSize, NewParentMenu, NewParentHost),
	CallbackGetValue(NewCallbackGetValue),
	Value(0.f),
	RawCaption(NewCaption),
	Format(NewFormat)
{
}

void Control_Value::Refresh()
{
	const float OldValue = Value;

	Value = CallbackGetValue();

	if (OldValue != Value)
		RefreshCaption();
}

void Control_Value::RefreshCaption()
{
	char StrBuffer[32];

	//sprintf_s(StrBuffer, "%.5f", Value);
	sprintf_s(StrBuffer, Format.c_str(), Value);
	Caption = RawCaption + StrBuffer;
}

Control_Value::~Control_Value()
{
}

void Control_Value::UpdateVerticesSlow(RendererComponent& Renderer)
{
	Control_Text::UpdateVerticesSlow(Renderer);
}

void Control_Value::UpdateVerticesFix(RendererComponent& Renderer)
{
	Control_Visible::UpdateVerticesFix(Renderer);
}
